package com.aynu.gulimall.search.web;

import com.aynu.gulimall.search.service.MallSearchService;
import com.aynu.gulimall.search.vo.SearchParam;
import com.aynu.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mj
 * @version 1.0
 * @date 2021/3/11 19:09
 */
@Controller
public class SearchController {

    @Autowired
    private MallSearchService searchService;

    @GetMapping("list.html")
    public String toListHtml(SearchParam param, Model model, HttpServletRequest request){
        //拿去查询条件
        param.set_url(request.getQueryString());
        //根据搜索添加,去es中检索商品
        SearchResult result = searchService.search(param);
        //封装返回前端的页面
        model.addAttribute("result",result);

        return "list";
    }
}
